<template>
  <div class="app-container">
    <div class="filter-container">
     
      <el-date-picker v-model="listQuery.month" style="width:150px;" format="yyyy-MM-dd" type="datetime" placeholder="选择月份" />
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" style="margin-top:8px" @click="handleFilter">查询</el-button>
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" style="margin-top:8px" @click="excelout">导出</el-button>

      <!-- <excelout /> -->
    </div>

    <!-- <el-row style="font-size:14px;color:#666">
        <el-col :span="4">已付金额：{{ counts.paid_money }}</el-col>
    </el-row> -->

    <el-table :key="tableKey" v-loading="listLoading" :data="list" size="mini" border fit highlight-current-row style="width: 100%;margin-top:20px">

      <el-table-column label="人员" align="center" width="100px">
        <template slot-scope="{row}">
          <span>{{ row.real_name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="M1" align="center" width="50px">
        <template slot-scope="{row}">
          <span>{{ row.model }}</span>
        </template>
      </el-table-column>
      <el-table-column label="M2" align="center" width="120px">
        <template slot-scope="{row}">
          <span>{{ row.sort_name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="M3" align="center" width="160px">
        <template slot-scope="{row}">
          <span>{{ row.bank_number }}</span>
        </template>
      </el-table-column>
      <el-table-column label="M4" align="center" width="200px">
        <template slot-scope="{row}">
          <span>{{ row.bank_address }}</span>
        </template>
      </el-table-column>
      <el-table-column label="M5" align="center" width="210px">
        <template slot-scope="{row}">
          <span>{{ row.pay_person }}</span>
        </template>
      </el-table-column>

      <el-table-column label="M6" align="center" width="100px">
        <template slot-scope="{row}">
          <span>{{ row.create_time }}</span>
        </template>
      </el-table-column>
      <el-table-column label="合计" align="center" width="80px">
        <template slot-scope="{row}">
          <span>{{ row.total_money }}</span>
        </template>
      </el-table-column>
      
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150px">
        <template slot-scope="{row,$index}">
          <el-button v-if="row.is_paid!=1" type="primary" size="mini" @click="onSubmit(row)">
            保存
          </el-button>
          <el-button v-if="row.is_paid==1" type="default" size="mini" @click="updateFirst(row)">
            修改
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
    <el-dialog title="详情" :visible.sync="detailAble" style="width:1000px;margin:auto">
     
     
    </el-dialog>
  
  </div>
</template>

<script>
import {
  getMerchantFirst, 
} from '@/api/finance'
import excelout from '@/components/excelout/index.vue'
import waves from '@/directive/waves' // waves directive
import {
  parseTime
} from '@/utils'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
export default {
  name: 'ComplexTable',
  components: {
    Pagination, excelout
  },
  directives: {
    waves
  },
  filters: {},
  data() {
    return {
      detailAble:false,
      tableKey: 0,
      tableRecord: 1,
      recordTotal: 0,
      total: 0,
      list:[],
      listLoading: true,
      listQuery: {
        month: '',
        page: 1,
        limit: 10,
      },
      merchant_list: [],
    }
  },
  created() {
    this.cacheQueryFormat()
    this.getList()
    // 添加钩子，页面刷新
    window.addEventListener('beforeunload', e => this.beforeunloadFn(e))
  },
  mdestroyed() {
    // 添加钩子，页面刷新
    window.removeEventListener('beforeunload', e => this.beforeunloadFn(e))
  },
  methods: {
  
    beforeunloadFn(e) {
      // 刷新页面事件
      sessionStorage.removeItem('commission')
    },
    cacheQueryFormat() {
      const cacheQuery = sessionStorage.getItem('commission')
      if (cacheQuery) {
        this.query = JSON.parse(cacheQuery)
      }
    },
 
    getList() {
      sessionStorage.setItem('finacefirst', JSON.stringify(this.query))
      getMerchantFirst(this.listQuery).then(response => {
        this.list = response.data.data
        this.total = response.data.total
        // this.counts = response.data.list.counts;
        // this.project = response.data.project;
        this.listLoading = false
      })
    },
  
    handleFilter() {
      this.getList()
    },
  
    excelout() {
      this.listLoading = true
      this.listQuery.page = 1
      this.listQuery.limit = this.total
      merchantFirstExcelout(this.listQuery).then(response => {
        this.listLoading = false
        const filepath = response.data.path
        window.location.href = filepath
      })
    },
   
  }
}
</script>
<style>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    white-space: nowrap;
  }
  select{
    width:100px;
  }

  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .tb-edit .input-box {
    display: none
  }
  .tb-edit .current-cell .input-box {
    display: block;
    margin-left: -15px;
  }

  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }

  .avatar {
    width: 178px;
    height: 178px;
    display: block;
    float: left;
  }
</style>
